<template>
  <!--修改密码-->
  <div class="search">
    <f-form :action="api.appuser.password" :form-key="formItem.userId" ref="form">
      <f-form-item label="密码" type="password" :required="true" :rules="rules.required(6,10)" :validator="validateToNextPassword" name="password" :value.sync="formItem.password"></f-form-item>
      <f-form-item label="确认密码" type="password" :required="true" :rules="rules.required(6,10)" :validator="compareToFirstPassword" name="passwordConfirm" :value.sync="formItem.passwordConfirm"></f-form-item>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'updatePassword',
    props: {},
    data () {
      return {
        isEdit: false,
        formItem: this.getFormItem()
      }
    },
    methods: {
      compareToFirstPassword (rule, value, callback) {
        if (value && value.length >= 6 && value !== this.formItem.password) {
          callback('2次密码不一致')
        } else {
          callback()
        }
      },
      validateToNextPassword (rule, value, callback) {
        const form = this.$refs.form.getForm()
        if (value) {
          form.validateFields(['passwordConfirm'], { force: 'change' })
        }
        callback()
      },
      getFormItem () {
        return {
          userId: '',
          password: '',
          passwordConfirm: ''
        }
      },
      setData (data) {
        this.formItem = this.getFormItem()
        this.$refs.form.resetFields()
        if (data && data.userId) {
          this.formItem.userId = data.userId
        }
      },
      handleSubmit () {
        this.$refs.form.submit({ userId: this.formItem.userId })
      }
    },
    created () {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
